//package com.yunhe.device.controller.device;
//
//import com.yunhe.device.domain.device.Analog;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.DomainList;
//import com.yunhe.common.model.PageParam;
//import com.yunhe.common.model.ResultObject;
//import com.yunhe.device.service.device.AnalogService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import com.yunhe.common.util.CollectionUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Optional;
//
///**
// * 点表Controller
// * @author liuronglei
// */
//@Api(value = "analog", description = "点表维护", tags = {"Model_Analog"})
//@RestController
//@RequestMapping("/analogs")
//public class AnalogController {
//    @Autowired
//    private AnalogService analogService;
//
//    /**
//     * 新增点表
//     * @param analog 点表对象
//     */
//    @ApiOperation("新增点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "svgCode", value = "SVG编号", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody Analog analog)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Analog newAnalog = analogService.createAnalog(analog);
//        return new ResponseEntity<>(new ResultObject<>(newAnalog), HttpStatus.OK);
//    }
//
//    /**
//     * 批量新增点表
//     * @param domainList 点表对象列表
//     */
//    @ApiOperation("批量新增点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "svgCode", value = "SVG编号", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/batch", method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody DomainList<Analog> domainList)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        List<Analog> analogList = domainList.getList();
//        Iterable<Analog> newAnalogs = analogService.createAnalog(analogList);
//        return new ResponseEntity<>(new ResultObject<>(newAnalogs), HttpStatus.OK);
//    }
//
//    /**
//     * 根据ID删除点表
//     * @param id 点表ID
//     */
//    @ApiOperation("根据ID删除点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "点表ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> delete(
//            @PathVariable("id") Long id) {
//        analogService.deleteAnalog(id);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    /**
//     * 根据点号删除点表
//     * @param pointNumber 点号
//     */
//    @ApiOperation("根据点号删除点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pointNumber", value = "点号", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/byPointNumber/{pointNumber}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> deleteByPointNumber(
//            @PathVariable("pointNumber") Long pointNumber) {
//        Long result = analogService.deleteAnalogByPointNumber(pointNumber);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
////    /**
////     * 根据条件获得点表列表（根据单位）
////
////     */
////    @ApiOperation("根据条件获得点表列表")
////    @ApiImplicitParams({
////            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
////    })
////    @RequestMapping(value = "/byFirm", method = RequestMethod.GET)
////    public ResponseEntity<ResultObject> search(
////                                               @ModelAttribute PageParam pageParam)
////            throws ObjectNotFoundException {
////        Iterable<Analog> results = analogService.findAnalogs(systemId);
////        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
////    }
//
//    /**
//     * 根据条件获得点表列表
//     */
//    @ApiOperation("根据条件获得点表列表")
//    @RequestMapping(method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByFirmCode(
//            @ModelAttribute PageParam pageParam) {
//        Iterable<Analog> results = analogService.findAnalogs();
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 根据点号获得点表列表
//     * @param pointNumber 点号
//     */
//    @ApiOperation("根据点号获得点表列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pointNumber", value = "点号", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/byPointNumber", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByPointNumber(
//            @RequestParam("pointNumber") Long pointNumber,
//            @ModelAttribute PageParam pageParam) {
//        Iterable<Analog> results = analogService.findAnalogsByPointNumber(pointNumber);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 根据设备代码和类型ID和端子获得点表列表
//     * @param devCode 设备代码
//     * @param typeCode 点号数据类型代码
//     */
//    @ApiOperation("根据设备代码和类型代码以及端子获得点表列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "devCode", value = "设备代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "meter", value = "表计编号", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/byDevAndType", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByDevCodeAndTypeCode(
//            @RequestParam("devCode") Long devCode,
//            @RequestParam("typeCode") Long typeCode,
//            @RequestParam("terminal") Optional<String> terminal,
//            @RequestParam("meter") Optional<String> meter) {
//        Analog result = analogService.findAnalogsByDevCodeAndTypeCode(devCode, typeCode,terminal.orElse(null),meter.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据设备ID和类型代码以及端子获得点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "devId", value = "设备ID", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "meter", value = "表计编号", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/byDevIdAndTypeCode", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByDevIdAndTypeCode(
//            @RequestParam("devId") Long devId,
//            @RequestParam("typeCode") Long typeCode,
//            @RequestParam("terminal") Optional<String> terminal,
//            @RequestParam("meter") Optional<String> meter) {
//        Analog result = null;
//        List<Analog> analogs = analogService.findAnalogsByDevIdAndTypeCode(devId, typeCode, terminal.orElse(null),meter.orElse(null));
//        if(CollectionUtil.isNotEmpty(analogs)){
//            result = analogs.get(0);
//        }
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据设备代码和类型代码获得点表列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "devCode", value = "设备代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/byDevCodeListAndTypeCodeList", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByDevCodeAndTypeCode(
//            @RequestParam("devCode") List<Long> devCodeList,
//            @RequestParam("typeCode") List<Long> typeCodeList) {
//        Iterable<Analog> result = analogService.findAnalogsByDevCodeAndTypeCode(devCodeList, typeCodeList);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * @param code 点表代码
//     */
//    @ApiOperation("删除点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "点表代码", required = true, dataType = "long", paramType = "path"),
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> deleteByCode(
//            @PathVariable("code") Long code) {
//        analogService.deleteAnalogByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    /**
//     * 修改点表
//     * @param code 点表代码
//     */
//    @ApiOperation("修改点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "点表代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.PUT)
//    public ResponseEntity<ResultObject> update(
//            @PathVariable("code") Long code,
//            @RequestBody Analog analog)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Analog newAnalog = analogService.updateAnalog(code, analog);
//        return new ResponseEntity<>(new ResultObject<>(newAnalog), HttpStatus.OK);
//    }
//
//    /**
//     * 获取点表
//     * @param code 点表code
//     */
//    @ApiOperation("获取点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "点表代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> get(
//            @PathVariable("code") Long code)
//            throws ArgumentErrorException {
//        Analog result = analogService.getAnalogsByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 修改点表（修改指定字段）
//     * @param code 点表代码
//     * @param name 点表编号
//     * @param title 标题
//     * @param pathName 路径名
//     * @param devCode 设备代码
//     * @param typeCode 点号数据类型代码
//     * @param pointNumber 点号
//     * @param transformRatio 倍率，默认1
//     * @param terminal 端子
//     * @param formula 公式
//     * @param isForShow 是否用于展示
//     * @param lowerLimit 下限值
//     * @param upperLimit 上限值
//     */
//    @ApiOperation("修改点表（修改指定字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "点表代码", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "name", value = "点表编号", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "title", value = "标题", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "pathName", value = "路径名", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "devCode", value = "设备代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "pointNumber", value = "点号", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "transformRatio", value = "倍率，默认1", dataType = "double", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "formula", value = "计算公式", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "isForShow", value = "是否用于展示", dataType = "boolean", paramType = "query"),
//            @ApiImplicitParam(name = "upperLimit", value = "上限值", dataType = "double", paramType = "query"),
//            @ApiImplicitParam(name = "lowerLimit", value = "下限值", dataType = "double", paramType = "query")
//    })
//    @RequestMapping(value = "byCode/{code}", method = RequestMethod.PATCH)
//    public ResponseEntity<ResultObject> patch(
//            @PathVariable("code") Long code,
//            @RequestParam("name") Optional<String> name,
//            @RequestParam("title") Optional<String> title,
//            @RequestParam("pathName") Optional<String> pathName,
//            @RequestParam("devCode") Optional<Long> devCode,
//            @RequestParam("typeCode") Optional<Long> typeCode,
//            @RequestParam("pointNumber") Optional<Long> pointNumber,
//            @RequestParam("transformRatio") Optional<Double> transformRatio,
//            @RequestParam("terminal") Optional<String> terminal,
//            @RequestParam("formula") Optional<String> formula,
//            @RequestParam("isForShow") Optional<Boolean> isForShow,
//            @RequestParam("lowerLimit") Optional<Double> lowerLimit,
//            @RequestParam("upperLimit") Optional<Double> upperLimit,
//            @RequestParam("sn") Optional<String> sn,
//            @RequestParam("officeName") Optional<String> officeName)
//            throws ArgumentErrorException, ObjectNotFoundException, UniqueConstraintsException {
//        Analog newAnalog = analogService.updateAnalogByCode(code, name.orElse(null), title.orElse(null),
//                pathName.orElse(null), devCode.orElse(null), typeCode.orElse(null), pointNumber.orElse(null),
//                transformRatio.orElse(null), terminal.orElse(null), formula.orElse(null), isForShow.orElse(null),
//                upperLimit.orElse(null), lowerLimit.orElse(null), sn.orElse(null), officeName.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(newAnalog), HttpStatus.OK);
//    }
//
//    /**
//     * 根据设备代码获取设备的全部点表
//     * @param devCode 设备代码
//     */
//    @ApiOperation("根据设备代码获取设备的全部点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "devCode", value = "设备代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "pointMeasureTypeCode", value = "四遥类型代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "isForShow", value = "是否展示", dataType = "boolean", paramType = "query")
//    })
//    @RequestMapping(value = "/byDevCode", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getAnalogsByDevCode(
//            @RequestParam("devCode") Long devCode,
//            @RequestParam("pointMeasureTypeCode") Optional<Long> pointMeasureTypeCode,
//            @RequestParam("isForShow") Optional<Boolean> isForShow) {
//        Iterable<Analog> results = analogService.getAnalogsByDevCode(devCode, pointMeasureTypeCode.orElse(null), isForShow.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 根据设备ID获取点表
//     * @param devIdList 设备ID列表
//     */
//    @ApiOperation("根据设备ID获取点表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "devIdList", value = "设备ID列表", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/byDevId", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findAnalogsByDevId(
//            @RequestParam("devIdList") List<Long> devIdList) {
//        Iterable<Analog> results = analogService.findAnalogsByDevId(devIdList);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 查找所有带公式的点号
//     */
//    @ApiOperation("查找所有带公式的点号")
////    @ApiImplicitParams({
////            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
////    })
//    @RequestMapping(value = "/hasFormula", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findAnalogsByFormulaNotNull() {
//        Iterable<Analog> results = analogService.findAnalogsByFormulaNotNull();
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据单位查询点号")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/byFirmCode", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findAnalogsByFirm(@PathVariable("systemId") Long systemId) {
//        Iterable<Analog> results = analogService.findAnalogsByFirm(systemId);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据单位查询云端计算虚拟点号")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/virtualAnalogs", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findVirtualAnalogs(@PathVariable("systemId") Long systemId) {
//        Iterable<Analog> results = analogService.findAnalogsByFormulaType(systemId, "web");
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 根据电池组和数据类型获得单体点号列表
//     * @param packId 电池组ID
//     * @param pointDataTypeCodeList 数据类型代码列表
//     */
//    @ApiOperation("根据电池组和数据类型获得单体点号列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "packId", value = "电池组ID", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "pointDataTypeCodeList", value = "数据类型代码列表（以逗号间隔）", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/batteryPnByPackAndDataType", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findBatteryPnByPackAndDataType(
//            @RequestParam("packId") Long packId,
//            @RequestParam("pointDataTypeCodeList") List<Long> pointDataTypeCodeList) {
//        List<Long> results = analogService.findBatteryPnByPackAndDataType(packId, pointDataTypeCodeList);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据单位ID、电站ID、企业ID、类型代码获得企业点表对应")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "firmId", value = "单位ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "stationId", value = "电站ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "companyId", value = "企业ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "meter", value = "表计", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/findCompanyPointNumber", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findCompanyPointNumber(
//            @RequestParam("firmId") Optional<Long> firmId,
//            @RequestParam("stationId") Optional<Long> stationId,
//            @RequestParam("companyId") Optional<Long> companyId,
//            @RequestParam("terminal") Optional<String> terminal,
//            @RequestParam("meter") Optional<String> meter,
//            @RequestParam("typeCode") Long typeCode) {
//        Map<Long, List<Long>> result = analogService.findCompanyPointNumber(firmId.orElse(null),
//                stationId.orElse(null), companyId.orElse(null),
//                typeCode, terminal.orElse(null), meter.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据单位ID、电站ID、类型代码获得电站点表对应")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "firmId", value = "单位ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "stationId", value = "电站ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "meter", value = "表计", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "点号数据类型代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/findStationPointNumber", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findStationPointNumber(
//            @RequestParam("firmId") Optional<Long> firmId,
//            @RequestParam("stationId") Optional<Long> stationId,
//            @RequestParam("terminal") Optional<String> terminal,
//            @RequestParam("meter") Optional<String> meter,
//            @RequestParam("typeCode") Long typeCode) {
//        Map<Long, List<Long>> result = analogService.findStationPointNumber(firmId.orElse(null),
//                stationId.orElse(null), typeCode, terminal.orElse(null), meter.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("获得企业表计列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "companyId", value = "企业ID", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "terminal", value = "端子", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/getMeter", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> findStationPointNumber(
//            @RequestParam("companyId") Long companyId,
//            @RequestParam("terminal") Optional<String> terminal) {
//        List<String> result = analogService.getMeterList(companyId, terminal.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    @ApiOperation("通过厂房编号查询所有绑定的点号信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "officeName", value = "厂房编号", required = true, dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/searchByOfficeName", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> searchByOfficeName(@RequestParam("officeName") String officeName) {
//        Iterable<Analog> result = analogService.searchByOfficeName(officeName);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//}